<?php
/**
 * 初始化后台
 * $Id: globals.php 236 2011-01-10 15:18:09Z bwanglei@gmail.com $
 */

require_once '../init.php';
define('TEMPLATE_PATH', AW_ROOT.'/templates/admin');
define('ADMIN_TEMP_URL', $blogUrl.'/templates/admin');

//读取缓存
$user_cache = $CACHE->readCache('users');

//登录验证
if ($action == 'login') {
	$username = isset($_POST['username']) ? $_POST['username'] : '';
	$password = isset($_POST['password']) ? $_POST['password'] : '';
	$img_code = isset($_POST['imgcode']) ? strtoupper($_POST['imgcode']) : '';

	if (checkUser($username, $password, $img_code) === true) {
		setAuthCookie($username, true);
		header('Location: ./');
	} else {
		loginPage();
	}
}

//登出
if ($action == 'logout') {
	setcookie(AUTH_COOKIE_NAME, ' ', time() - 31536000, '/');
	formMsg('退出成功！', '../',1);
}
if (ISLOGIN === false) loginPage();
